/********************************************************************

Class: Singleton< Ty > - C++ implementation of Singleton

Write Date: 2010/07/21
Author: Deng Nianchen
>>>> Implements basic Singleton design pattern.
	
*********************************************************************/
#ifndef SINGLETON_HPP
#define SINGLETON_HPP
#include "Global.hpp"



_OOPUTILS_BEGIN



/**************************************************************************************************
 * <summary>  Singleton implements application-slope object management. 
 * 						All classes derived from it will only have one object when 
 * 						the application is running. You can use an singleton object 
 * 						anywhere by call its getSingleton () or getSingletonPtr (). 
 * 						You needn't (and also shouldn't) construct an singleton 
 * 						object or destruct it manually. It will be automatically 
 * 						created when you first use it and be destoried when the 
 * 						application exits. 
 * 						Thread-safe: It is not thread-safe in current implementation. </summary>
 *
 * <remarks>  Deng Nianchen, 2011/3/24. </remarks>
 **************************************************************************************************/

template< class T >
class Singleton
{

protected:

  Singleton () {}
  Singleton (const Singleton&) {}
  Singleton & operator= (const Singleton&) { return (*this); }

public:

  /**************************************************************************************************
   * <summary>  Gets the singleton object reference. </summary>
   *
   * <remarks>  Deng Nianchen, 2011/3/24. </remarks>
   *
   * <returns>  The singleton reference. </returns>
   **************************************************************************************************/

  static T & getSingleton ()
  {
    static T singleton;
    return singleton;
  }

  /**************************************************************************************************
   * <summary>  Gets the singleton object pointer. </summary>
   *
   * <remarks>  Deng Nianchen, 2011/3/24. </remarks>
   *
   * <returns>  The singleton pointer. </returns>
   **************************************************************************************************/

  static T * getSingletonPtr ()
  {
    return &getSingleton ();
  }



};



_OOPUTILS_END



#endif